<?php

class IndexController extends Controller{
	/**
	 *登录
	 */
	public function loginAction() {
		if(empty($_POST)) {
			require CURR_VIEW_DIR . "login.htm";
		} else {
			$admin_name = $_POST['username'];
			$admin_passwd = $_POST['pwd'];
			$model = new AdminModel;
			$a = $model -> checkLogin($admin_name,$admin_passwd);
			if($model -> checkLogin($admin_name,$admin_passwd)) {
				setcookie('is_login','1',time()+3600);
				$this->jump(3,'./index.php?p=back&c=Index&a=index',"登录成功");
			} else {
				$this->jump(3,'./index.php?p=back&c=Index&a=login',"登录失败");
			}
		}
	}
	/**
	 *展示后台首页
	 */
	public function indexAction() {
		if(isset($_COOKIE['is_login']) && $_COOKIE['is_login'] == 1) {
			require CURR_VIEW_DIR . "index.htm";	
		} else {
			$this->jump(3,'./index.php?p=back&c=Index&a=login',"请登录");
		}
	}
	/**
	 *退出登录
	 */
	public function logoutAction() {
		setCookie('is_login',0);
		$this->jump(3,'./index.php?p=back&c=Index&a=login',"请登录");
	}
}